package com.bitnpulse.dev2.jjh.engstudybook_free.dialog;

import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.bitnpulse.dev2.jjh.engstudybook_free.R;
import com.bitnpulse.dev2.jjh.engstudybook_free.beans.WordBean;

public class WordDialog extends CustomDialog implements android.view.View.OnClickListener{
	
	public WordDialog(Context context, WordBean contentsBean) {
		super(context);
		initialize();
		setContentView(R.layout.popup_word);
		initializeView(contentsBean);
	}
	
	private void initialize(){
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//		this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		this.setCancelable(true);
		this.setCanceledOnTouchOutside(true);
	}
	
	private void initializeView(WordBean contentsBean){
		
		((TextView)findViewById(R.id.txt_main)).setText(contentsBean.mainTitle);
		
		if(contentsBean.Title1.isEmpty()){
			findViewById(R.id.txt_title1).setVisibility(View.GONE);
		}else{
			findViewById(R.id.txt_title1).setVisibility(View.VISIBLE);
			((TextView)findViewById(R.id.txt_title1)).setText(contentsBean.Title1);
		}
		
		((TextView)findViewById(R.id.txt_Contents1)).setText(contentsBean.Text1);
		
		if(contentsBean.Title2.isEmpty()){
			findViewById(R.id.txt_title2).setVisibility(View.GONE);
			findViewById(R.id.txt_Contents2).setVisibility(View.GONE);
		}else{
			findViewById(R.id.txt_title2).setVisibility(View.VISIBLE);
			findViewById(R.id.txt_Contents2).setVisibility(View.VISIBLE);
			((TextView)findViewById(R.id.txt_title2)).setText(contentsBean.Title2);
			((TextView)findViewById(R.id.txt_Contents2)).setText(contentsBean.Text2);
		}
		
		if(contentsBean.Title3.isEmpty()){
			findViewById(R.id.txt_title3).setVisibility(View.GONE);
			findViewById(R.id.txt_Contents3).setVisibility(View.GONE);
		}else{
			findViewById(R.id.txt_title3).setVisibility(View.VISIBLE);
			findViewById(R.id.txt_Contents3).setVisibility(View.VISIBLE);
			((TextView)findViewById(R.id.txt_title3)).setText(contentsBean.Title3);
			((TextView)findViewById(R.id.txt_Contents3)).setText(contentsBean.Text3);
		}
		
		Button btnDialogClose = (Button)findViewById(R.id.btnDialogClose);
		btnDialogClose.setOnClickListener(WordDialog.this);
	}
	
	@Override
	public void onClick(View v) {
		this.dismiss();
	}

}
